package com.xuhai.blog19.admin.controller;

import com.xuhai.blog19.admin.entity.BannerEntity;
import com.xuhai.blog19.admin.service.BannerService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2023/2/8/008
 */
@RestController
@RequestMapping("/admin/href")
public class HrefController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("/page")
    public R page(int page, int limit, BannerEntity banner) {
        banner.setType(2);
        return R.ok().data(bannerService.getPage(page, limit, banner));
    }

    @GetMapping("/info/{bannerId}")
    public R info(@PathVariable Integer bannerId) {
        return R.ok().data(bannerService.getById(bannerId));
    }

    @PostMapping("/update")
    public R update(@RequestBody BannerEntity banner) {
        banner.setType(2);
        bannerService.saveOrUpdate(banner);
        return R.ok();
    }

    @DeleteMapping("/delete/{bannerId}")
    public R delete(@PathVariable Integer bannerId) {
        bannerService.removeById(bannerId);
        return R.ok();
    }
}
